package com.ruoyi.common.core.page;

import com.github.pagehelper.PageInfo;

import java.util.List;

/**
 * @author ZZH
 * @version 1.0
 */
public class MySetPage extends TableDataInfo{
    public static TableDataInfo mySetPage(List list){

        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        TableDataInfo rspData =new TableDataInfo();
        rspData.setCode(0);
        rspData.setRows(myStartPage(list, pageNum, pageSize));
        rspData.setTotal(new PageInfo(list).getTotal());
        return rspData;

    }


    public static List myStartPage(List list, Integer pageNum, Integer pageSize){
        if(list ==null){
            return null;
        }
        if(list.size()==0){
            return null;
        }
        Integer count = list.size();//
        Integer pageCount =0;//
        if(count % pageSize ==0){
            pageCount = count / pageSize;
        }else{
            pageCount = count / pageSize +1;
        }
        int fromIndex =0;//
        int toIndex =0;//
        if(pageNum != pageCount){
            fromIndex =(pageNum -1)* pageSize;
            toIndex = fromIndex + pageSize;
        }else{
            fromIndex =(pageNum -1)* pageSize;
            toIndex = count;
        }
        List pageList = list.subList(fromIndex,toIndex);
        return pageList;
    }


}
